package com.uaaone.service;

import com.alibaba.fastjson.JSON;
import com.uaaone.entity.CustomUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author iszengziqiang@163.com
 * @date 2021-08-25 15:42
 * @Version: 1.0
 * @desc
 */
@Slf4j
@Service
public class UserService implements UserDetailsService {
    @Autowired
    TUserService tUserService;

    @Autowired
    TUserRoleService tUserRoleService;

    @Autowired
    TRoleService tRoleService;


    /**
     * Locates the user based on the username. In the actual implementation, the search
     * may possibly be case sensitive, or case insensitive depending on how the
     * implementation instance is configured. In this case, the <code>UserDetails</code>
     * object that comes back may have a username that is of a different case than what
     * was actually requested..
     *
     * @param username the username identifying the user whose data is required.
     * @return a fully populated user record (never <code>null</code>)
     * @throws UsernameNotFoundException if the user could not be found or the user has no
     *                                   GrantedAuthority
     */
    @Override
    public CustomUser loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println("用户名是：" + username + "####");
        // 判断成功后返回用户细节
        CustomUser c = new CustomUser();
        c.setUsername(username);
        c.setPassword(new BCryptPasswordEncoder().encode("123456"));
        System.out.println(JSON.toJSONString(c));
        return c;
    }

    public static void main(String[] args) {
        System.out.println(new BCryptPasswordEncoder().encode("123456"));
    }
}
